package com.zut.Service.registerService.registerImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zut.Dao.UserInfoDao;
import com.zut.Pojo.UserInfo;
import com.zut.Service.registerService.register;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

@Service("com.zut.Service.registerService")
public class registerImpl implements register {
    @Autowired
    private UserInfoDao userInfoDao;

    //TODO 有漏洞
    @Override
    public UserInfo register(UserInfo userInfo) {
        //查询数据库是否有相关数据,手机号是唯一的
        UserInfo boolUser = userInfoDao.selectOne(new QueryWrapper<>
                (UserInfo.builder().phone(userInfo.getPhone())
                        .build()));
        //如果很空，注册相关信息
        if(Objects.isNull(boolUser)){
             userInfoDao.insert(userInfo);
             return userInfo;
        }
        //不是直接返回
        return null;
    }
}
